<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <table border="1">
        <caption>员工列表</caption>
        <tr><th>id</th><th>名字</th><th>工作</th><th>工资</th><th>操作</th></tr>
        <tr v-for="emp in arr">
            <td>{{emp.id}}</td>
            <td>{{emp.name}}</td>
            <td>{{emp.job}}</td>
            <td>{{emp.sal}}</td>
            <!--href="javascript:void(0)"：将超链接的初始跳转功能废除-->
            <td>
                <a href="javascript:void(0)" @click="del(emp.id)">删除</a>
                <a :href="'update.html?id='+emp.id">修改</a>
            </td>
        </tr>
    </table>
<!--引入axios和vue-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.js"></script>
<script>
    let v = new Vue({
        el:"table",
        data:{
            arr:[{id:4,name:"刘备",job:"打野",sal:6888},
                {id:2,name:"关羽",job:"战士",sal:8888},
                {id:3,name:"张飞",job:"辅助",sal:12888}]
        },
        methods:{
            del(id){
                axios.post("/delete?id="+id).then(function () {
                    //刷新本页面
                    location.reload();
                })
            }
        },
        created(){
            //页面加载完毕后，立刻执行的代码
            //f发起异步请求，获取员工数据
            axios.get("/select").then(function (response) {
                v.arr = response.data;
            })
        }
    })
</script>

</body>
</html>